package com.ruoyi.bearing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bearing.domain.BearingDataset;
import com.ruoyi.bearing.service.IBearingDatasetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据集Controller
 */
@Api("轴承数据集管理")
@RestController
@RequestMapping("/bearingData/dataset")
public class BearingDatasetController extends BaseController
{
    @Autowired
    private IBearingDatasetService bearingDatasetService;

    /**
     * 查询数据集列表
     */
    @ApiOperation("查询数据集列表")
    @PreAuthorize("@ss.hasPermi('bearingData:dataset:list')")
    @GetMapping("/list")
    public TableDataInfo list(BearingDataset bearingDataset)
    {
        startPage();
        List<BearingDataset> list = bearingDatasetService.selectBearingDatasetList(bearingDataset);
        return getDataTable(list);
    }

    /**
     * 导出数据集列表
     */
    @ApiOperation("导出数据集列表")
    @PreAuthorize("@ss.hasPermi('bearingData:dataset:export')")
    @Log(title = "数据集", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BearingDataset bearingDataset)
    {
        List<BearingDataset> list = bearingDatasetService.selectBearingDatasetList(bearingDataset);
        ExcelUtil<BearingDataset> util = new ExcelUtil<BearingDataset>(BearingDataset.class);
        util.exportExcel(response, list, "数据集数据");
    }

    /**
     * 获取数据集详细信息
     */
    @ApiOperation("获取数据集详细信息")
    @PreAuthorize("@ss.hasPermi('bearingData:dataset:query')")
    @GetMapping(value = "/{datasetId}")
    public AjaxResult getInfo(@PathVariable("datasetId") String datasetId)
    {
        return success(bearingDatasetService.selectBearingDatasetByDatasetId(datasetId));
    }

    /**
     * 新增数据集
     */
    @ApiOperation("新增数据集")
    @PreAuthorize("@ss.hasPermi('bearingData:dataset:add')")
    @Log(title = "数据集", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BearingDataset bearingDataset)
    {
        return toAjax(bearingDatasetService.insertBearingDataset(bearingDataset));
    }

    /**
     * 修改数据集
     */
    @ApiOperation("修改数据集")
    @PreAuthorize("@ss.hasPermi('bearingData:dataset:edit')")
    @Log(title = "数据集", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BearingDataset bearingDataset)
    {
        return toAjax(bearingDatasetService.updateBearingDataset(bearingDataset));
    }

    /**
     * 删除数据集
     */
    @ApiOperation("删除数据集")
    @PreAuthorize("@ss.hasPermi('bearingData:dataset:remove')")
    @Log(title = "数据集", businessType = BusinessType.DELETE)
	@DeleteMapping("/{datasetIds}")
    public AjaxResult remove(@PathVariable String[] datasetIds)
    {
        return toAjax(bearingDatasetService.deleteBearingDatasetByDatasetIds(datasetIds));
    }
}
